**Import stata dta file

drop if Drop==1

**score for message reasonableness (whatever condition respondent was assigned to)
egen treatment_reason = rowmax(MMRPReason TJRPReason MMDETReason TJDETReason MMZReason TJZReason)

**perceived emotion of speaker (whatever condition respondent was assigned to)
egen treatment_sad = rowmax(MMRPSad TJRPSad MMDETSad TJDETSad MMZSad TJZSad)
replace treatment_sad=0 if treatment_sad==.
egen treatment_angry = rowmax(MMRPAngry TJRPAngry MMDETAngry TJDETAngry MMZAngry TJZAngry)
replace treatment_angry=0 if treatment_angry==.
egen treatment_anxious = rowmax(MMRPAnxious TJRPAnxious MMDETAnxious TJDETAnxious MMZAnxious TJZAnxious)
replace treatment_anxious=0 if treatment_anxious==.
egen treatment_frustrated = rowmax(MMRPFrustrated TJRPFrustrated MMDETFrustrated  TJDETFrustrated  MMZFrustrated  TJZFrustrated)
replace treatment_frustrated=0 if treatment_frustrated==.
egen treatment_cynical = rowmax(MMRPCynical TJRPCynical MMDETCynical  TJDETCynical  MMZCynical  TJZCynical)
replace treatment_cynical=0 if treatment_cynical==.
egen treatment_optimistic = rowmax(MMRPOptimistic TJRPOptimistic MMDETOptimistic TJDETOptimistic MMZOptimistic TJZOptimistic)
replace treatment_optimistic=0 if treatment_optimistic==.
egen treatment_calm = rowmax(MMRPCalm TJRPCalm  MMDETCalm  TJDETCalm  MMZCalm  TJZCalm)
replace treatment_calm=0 if treatment_calm==.

**number of words expended on free response sections
egen treatment_sumcount = rowmax(MMRPSumCount TJRPSumCount MMDETSumCount TJDETSumCount MMZSumCount TJZSumCount)
egen treatment_optioncount = rowmax(MMRPOptionCount TJRPOptionCount MMDETOptionCount TJDETOptionCount MMZOptionCount TJZOptionCount)
gen treatment_totaleffort = treatment_sumcount+treatment_optioncount

**relabel of experimental conditions
label define treatment1 1 "Rowdy Party MM" 2 "Rowdy Party TJ" 3 "DET MM" 4 "DET TJ" 5 "Zoning MM" 6 "Zoning TJ" 
label values treatment treatment1
tab treatment

**relabel of control group and treatment groups
gen contrlvstreat=1 if treatment==1|treatment==2
replace contrlvstreat=2 if treatment==3|treatment==4
replace contrlvstreat=3 if treatment==5|treatment==6
label define contrlvstreat1 1 "Control Cond RP" 2 "DET Cond" 3 "Zoning Cond"
label values contrlvstreat contrlvstreat1

**relabel black vs white actor/speaker
gen blackspeaker=1 if treatment==2|treatment==4|treatment==6
replace blackspeaker=0 if treatment==1|treatment==3|treatment==5
label define blackspeaker1 1 "Black" 0 "White"
label values blackspeaker blackspeaker1
tab blackspeaker

**respondent race
encode other, gen(otherrace)
gen whiteonly=1 if (white==1 & black==. &  latino==. & asian==. & native_amer==. & otherrace==.)
replace whiteonly=0 if whiteonly==.
gen blackonly=1 if (white==. & black==1 &  latino==. & asian==. & native_amer==. & otherrace==.)
replace blackonly=0 if blackonly==.
gen latinoonly=1 if (white==. & black==. &  latino==1 & asian==. & native_amer==. & otherrace==.)
replace latinoonly=0 if latinoonly==.
gen asianonly=1 if (white==. & black==. &  latino==. & asian==1 & native_amer==. & otherrace==.)
replace asianonly=0 if asianonly==.


gen race=1 if whiteonly==1
replace race=2 if blackonly==1
replace race=3 if latinoonly==1
replace race=4 if asianonly==1
replace race=5 if race==.

label define race1 1 "White" 2 "Black" 3 "Latino" 4 "Asian" 5 "Other/MultiRace"
label values race race1
tab race

gen racedum=1 if race==1
replace racedum=0 if racedum==.
label define racedum1 1 "white" 0 "nonwhite"
label values racedum racedum1
tab racedum

**respondent gender
label define gender1 1 "Male" 2 "Female" 3 "Nonconforming"
label values gender gender1

gen genderdum=1 if gender==1
replace genderdum=0 if gender==2|gender==3
label define genderdum1 1 "Male" 0 "Female/Nonconforming/Transgender"
label values genderdum genderdum1

**respondent ideology 
label define ideology1 1 "Very Liberal" 2 "Liberal" 3 "Moderate" 4 "Conservative" 5 "Very Conservative" 6 "Other"
label values ideology ideology1

**condensed ideological categories
gen ideocat=1 if ideology==1|ideology==2| Response_id==149069275
replace ideocat=2 if ideology==3|Response_id==149060584| Response_id==149197012| Response_id==149121759
replace ideocat=3 if ideology==4|ideology==5
label define ideocat1 1 "Very Liberal/Liberal" 2 "Moderate" 3 "Very Conservative/Conservative"
label values ideocat ideocat1

**respondent age 
label define age1 1 "18-29" 2 "30-39" 3 "40-49" 4 "50 or above"
label values age age1

**respondent education
label define educ1 1 "no HS degree" 2 "HS Degree" 3 "2-Year College" 4 "4-Year College" 5 "Graduate Degree" 6 "Other"
label values educ educ1

**respondent income
label define income1 1 "less than $50K" 2 "$50K-$100K" 3 "over $100K"
label values income income1


***************************************************************************************************************************************************

**regression model for evaluation
*Overall Black-White Difference
regress treatment_reason i.blackspeaker, vce(robust)
margins blackspeaker
margins, dydx(blackspeaker)
*Black-White Difference for control condition
regress treatment_reason i.contrlvstreat##i.blackspeaker, vce(robust)
*Black-White Difference for DE Training condition
regress treatment_reason ib2.contrlvstreat##i.blackspeaker, vce(robust)
*Black-White Difference for zoning condition
regress treatment_reason ib3.contrlvstreat##i.blackspeaker, vce(robust)
*mean evaluation for Black and White speaker for each condition
margins blackspeaker, at(contrlvstreat=(1/3))
*Difference in means between Black and White for each condition
margins, dydx(blackspeaker) at(contrlvstreat=(1/3))

**logit models for perception of emotions
logit treatment_calm i.blackspeaker##i.contrlvstreat treatment_angry treatment_frustrated
margins blackspeaker, at(contrlvstreat=(1/3)) 
margins, dydx(blackspeaker) at(contrlvstreat=(1/3))
logit treatment_angry i.blackspeaker##i.contrlvstreat treatment_calm treatment_frustrated
margins blackspeaker, at(contrlvstreat=(1/3))
margins, dydx(blackspeaker) at(contrlvstreat=(1/3))
logit treatment_frustrated i.blackspeaker##i.contrlvstreat treatment_calm treatment_angry
margins blackspeaker, at(contrlvstreat=(1/3))
margins, dydx(blackspeaker) at(contrlvstreat=(1/3))

**the effect of speaker race conditional upon statement and emotion
regress treatment_reason i.contrlvstreat##i.blackspeaker##i.treatment_calm i.treatment_angry i.treatment_frustrated, vce(robust)
margins blackspeaker, at(contrlvstreat=(1/3) treatment_calm=(0/1))
margins, dydx(blackspeaker) at(contrlvstreat=(1/3) treatment_calm=(0/1))

regress treatment_reason i.contrlvstreat##i.blackspeaker##i.treatment_angry i.treatment_calm i.treatment_frustrated, vce(robust)
margins blackspeaker, at(contrlvstreat=(1/3) treatment_angry=(0/1))
margins, dydx(blackspeaker) at(contrlvstreat=(1/3) treatment_angry=(0/1))

regress treatment_reason i.contrlvstreat##i.blackspeaker##i.treatment_frustrated i.treatment_calm i.treatment_angry, vce(robust)
margins blackspeaker, at(contrlvstreat=(1/3) treatment_frustrated=(0/1))
margins, dydx(blackspeaker) at(contrlvstreat=(1/3) treatment_frustrated=(0/1))

**Supplementary Analysis

**Controlling for age
regress treatment_reason i.contrlvstreat##i.blackspeaker i.age, vce(robust)
regress treatment_reason ib2.contrlvstreat##i.blackspeaker i.age, vce(robust)
regress treatment_reason ib3.contrlvstreat##i.blackspeaker i.age, vce(robust)

**controlling for perceived emotional disposition and age
regress treatment_reason i.contrlvstreat##i.blackspeaker i.treatment_calm i.treatment_angry i.treatment_frustrated i.age, vce(robust)
regress treatment_reason ib2.contrlvstreat##i.blackspeaker i.treatment_calm i.treatment_angry i.treatment_frustrated i.age, vce(robust)
regress treatment_reason ib3.contrlvstreat##i.blackspeaker i.treatment_calm i.treatment_angry i.treatment_frustrated i.age, vce(robust)


**ologit model for reasonableness ranking
**black/white difference in rowdy party condition
ologit treatment_reason i.contrlvstreat##i.blackspeaker i.age
**black/white difference in de-escalation training condition
ologit treatment_reason ib2.contrlvstreat##i.blackspeaker i.age
**black/white difference in zoning condition
ologit treatment_reason ib3.contrlvstreat##i.blackspeaker i.age
**predicted probabilities and changes in marginal predictions for each outcome
margins, dydx(blackspeaker) at(contrlvstreat=(1/3) age=4) predict(outcome(5))
margins (blackspeaker), at(contrlvstreat=(1/3) age=4) predict(outcome(5))
margins, dydx(blackspeaker) at(contrlvstreat=(1/3) age=4) predict(outcome(4))
margins (blackspeaker), at(contrlvstreat=(1/3) age=4) predict(outcome(4))
margins, dydx(blackspeaker) at(contrlvstreat=(1/3) age=4) predict(outcome(3))
margins (blackspeaker), at(contrlvstreat=(1/3) age=4) predict(outcome(3))
margins, dydx(blackspeaker) at(contrlvstreat=(1/3) age=4) predict(outcome(2))
margins (blackspeaker), at(contrlvstreat=(1/3) age=4) predict(outcome(2))
margins, dydx(blackspeaker) at(contrlvstreat=(1/3) age=4) predict(outcome(1))
margins (blackspeaker), at(contrlvstreat=(1/3) age=4) predict(outcome(1))

**To determine if demographic characteristics are randomly distributed among/not associated with treatment conditions
mlogit treatment i.race i.genderdum i.educ i.income i.ideology i.age

